package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.result.Result;
import com.sky.utils.HuaWeiOBSUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Author FengHuan Wang
 * @Date 2024/12/29 15:51
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/admin/common")
@Api("公共控制器")
public class CommonController {

    @Autowired
    private HuaWeiOBSUtils huaWeiOBSUtils;
    /*菜品上传功能*/
    @PostMapping("/upload")
    @ApiOperation("菜品上传")
    public Result<String> upload(MultipartFile file){
        try {
            log.info("开始上传菜品");
            String path = huaWeiOBSUtils.upload(file);
            return Result.success(path);
        } catch (IOException e) {
            log.error("图片上传失败");
        }
        return Result.error(MessageConstant.UPLOAD_FAILED);
    }

}
